package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.ParkingLot;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ParkingLotMapper extends BaseMapper<ParkingLot> {
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "pricing_standard_id",property = "pricingStandard",one =@One(select = "com.example.demo.mapper.PricingStandardMapper.selectById"))
    })
    @Select("select * from parking_lot join pricing_standard " +
            "on pricing_standard.id=parking_lot.pricing_standard_id")
    List<ParkingLot> getAll();

    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "pricing_standard_id",property = "pricingStandard",one =@One(select = "com.example.demo.mapper.PricingStandardMapper.selectById"))
    })
    @Select("select * from parking_lot join pricing_standard " +
            "on pricing_standard.id=parking_lot.pricing_standard_id" +
            " where parking_lot.id=#{id}")
    ParkingLot getById(Long id);

    @Insert("insert into parking_lot set name=#{name}" +
            " ,volumetric=#{volumetric}" +
            ",pricing_standard_id=#{pricingStandardId}")
    int insert(ParkingLot entity);

    @Update("update parking_lot set name=#{name}" +
            ",volumetric=#{volumetric}" +
            ",pricing_standard_id=#{pricingStandardId}" +
            " where id=#{id}")
    int update(ParkingLot entity);

}
